clc; clear; close all;

%Generates price impact for different numbers of contracts and then
%normalizes it for comparison with Gabaix-Koijen

load('intermediate\CompileAllCIPCalcs.mat')

%Calculate maximum arb closing sizes
maxArbClSizes  = max(abs(WelfareArbs2(:, [2 4 6 8 10]))*1e6);
meanArbClSizes = mean(abs(WelfareArbs2(:,[2 4 6 8 10]))*1e6);

%GDP of various economies using 2019 GDP
GDPs = [1.4e12 2.83e12 1.74e12 1.83e13 5.08e12];

PriceImpactFunctions = zeros(3,5);
GabaixKoijenStyleMultipliers = zeros(3,5);
TradeSizesInDollars = zeros(3,5);
TradeSizesInPercentGDP = zeros(3,5);
counter = 0;
while(counter<5)
   counter = counter+1;
   %Test Trades at $50M, $100M, $1B
   Levels = [5e7 1e8 1e9];
   contracts = Levels./(Multipliers(counter)*valsForSumStats2(2,counter));
   PriceImpactFunctions(:,counter) = (TickSizes(counter)/valsForSumStats2(2,counter))*(alphas(1,counter)*(contracts.^0.5))';
   TradeSizesInDollars = Levels';
   TradeSizesInPercentGDP(:,counter) = (Levels./GDPs(1,counter))'; %Fraction format 0.01=1%
   GabaixKoijenStyleMultipliers(:,counter)=(PriceImpactFunctions(:,counter)./TradeSizesInPercentGDP(:,counter));
end

%GabaixKoijenStyleMultipliers has multipliers in the style of Gabaix and
%Koijen with columns representing currencies per usual and rows
%representing 5 different trade sizes: 1 contract (minimum tradable quantity
%in futures), the average arb-closing trade size, the maximum arb-closing
%trade size, $500M, and $100B

%PriceImpactFunctions contains the percentage impact expressed as a
%fraction for the various currency pairs and trade sizes

%Table lists the multipliers based on answering the question "by what
%percent does the currency move relative to the fraction of GDP that the
%trade represents"
GabaixKoijenTableValues = GabaixKoijenStyleMultipliers;
GabaixKoijenColHeadings = {'AUD/USD','GBP/USD','CAD/USD','EUR/USD','JPY/USD'};
GabaixKoijenRowHeadings = {'$50M Trade','$100M Trade','$1B Trade'}';

% save('intermediate\GabaixKoijenStyleMultipliers')
save('intermediate\GabaixKoijenStyleMultipliersTable','GabaixKoijenTableValues','GabaixKoijenColHeadings','GabaixKoijenRowHeadings','PriceImpactFunctions','TradeSizesInPercentGDP')